#ifndef DXGRAPH_H_
#define DXGRAPH_H_

#include <InitGuid.h>
#include <DShow.h>
#include <comdef.h>
#include <atlbase.h>
#define WM_GRAPHNOTIFY  (WM_USER+20)

class CDXGraph
{
public:
	CDXGraph();
	virtual ~CDXGraph();

private:
	IGraphBuilder* m_pGraph;
	IMediaControl* m_pMediaCtrl;
	IMediaEventEx* m_pEvent;
	IBasicAudio* m_pBasicAudio;
	IBasicVideo* m_pBasicVideo;
	IVideoWindow* m_pVideoWindow;
	IMediaSeeking* m_pSeeking;

	IBaseFilter* m_BasicSource;
	IBaseFilter* m_ARenderer;
	IBaseFilter* m_VRenderer;
	IBaseFilter* m_RMSplitter;
	IBaseFilter* m_RMADecoder;
	IBaseFilter* m_RMVDecoder;

	DWORD m_objTableEntry;
	CRect m_rcActive;
public:
	bool Create();
	void	Release();
	bool Run();
	bool IsRunning();
	bool Stop();
	bool IsStopped();
	bool Pause();
	bool IsPause();

	IMediaEventEx* GetEventHandle(void);

	bool SetFullScreen(bool inEnable);
	bool GetFullScreen(void);
	bool SetCurrentPosition(double inPosition);
	bool GetCurrentPosition(double* outPosition);
	bool SetAudioVolume(long inVolume);
	bool GetDuration(double* outDuration);
	bool RenderFile(const char* inFile);
	bool SetNotifyWindow(HWND inWindow);
	bool SetDisplayWindow(HWND inWindow);
	void AddToObjectTable(void);
	void RemoveFromObjectTable(void);
	bool QueryInterface(void);
	bool GetVideoSize(CRect rc);
	void ShowVideoWindow(long cx, long cy);

	HRESULT AddFilterByCLSID(IGraphBuilder *pGraph, const GUID &clisd, LPCWSTR wszName, IBaseFilter **ppF);
	HRESULT ConnectFilters(IGraphBuilder *pGraph, IPin *pOut, IBaseFilter *pDest);
	HRESULT ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pSrc, IBaseFilter *pDest);
	HRESULT GetUnconnectedPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin);
};

#endif